package com.group9.handinhand.service.so;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.ArrayUtils;

import com.group9.handinhand.dao.model.Community;
import com.group9.handinhand.dao.model.CommunityCategory;
import com.group9.handinhand.service.so.CommunityEnums.CommunityPrivacy;
import com.group9.handinhand.service.so.CommunityEnums.RequiredPermissionToSubscribe;
/**
 * Class for services for community
 *
 */
public class CommunitySO extends AbstractBaseSO {
	
	private String name;
	private String description;
	private CommunityCategory category;
	private CommunityPrivacy privacy = CommunityPrivacy.PUBLIC;
	private RequiredPermissionToSubscribe permission = RequiredPermissionToSubscribe.NONE;
	private Set<UserSO> moderators = new HashSet<UserSO>();
	private Set<CommunityPostSO> posts = new HashSet<CommunityPostSO>();
	private Set<EventSO> events = new HashSet<EventSO>();
	private Set<RequestSO> requests = new HashSet<RequestSO>();
	private Set<OfferSO> offers = new HashSet<OfferSO>();
	private Set<CommunityMemberSO> members = new HashSet<CommunityMemberSO>();
	/**
	 * converts the community model object
	 * @param ignoreProperties
	 * @return
	 */
	public Community convertToModelObject(String... ignoreProperties) {
		Community model = (Community) convert(new Community(), 
			(String[]) ArrayUtils.addAll(ignoreProperties,new String[]{"moderators", "posts", "events","requests","offers","members"}));
		if( ! Arrays.asList(ignoreProperties).contains("moderators"))
			for (UserSO user : moderators) {
				model.getModerators().add(user.convertToModelObject(new String[]{"socialUsers"}));
			}
		if (!Arrays.asList(ignoreProperties).contains("posts"))
			for (CommunityPostSO post : posts) {
				model.getPosts().add(post.convertToModelObject());
			}
		if (!Arrays.asList(ignoreProperties).contains("events"))
			for (EventSO event : events) {
				model.getEvents().add(event.convertToModelObject());
			}
		if (!Arrays.asList(ignoreProperties).contains("requests"))
			for (RequestSO request : requests) {
				model.getRequests().add(request.convertToModelObject());
			}
		if (!Arrays.asList(ignoreProperties).contains("offers"))
			for (OfferSO offer : offers) {
				model.getOffers().add(offer.convertToModelObject());
			}
		if (!Arrays.asList(ignoreProperties).contains("members"))
			for (CommunityMemberSO member : members) {
				model.getMembers().add(member.convertToModelObject());
			}

		return model;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public Set<CommunityPostSO> getPosts() {
		return posts;
	}

	public void setPosts(Set<CommunityPostSO> posts) {
		this.posts = posts;
	}

	public CommunityCategory getCategory() {
		return category;
	}

	public void setCategory(CommunityCategory category) {
		this.category = category;
	}

	public CommunityPrivacy getPrivacy() {
		return privacy;
	}

	public void setPrivacy(CommunityPrivacy privacy) {
		this.privacy = privacy;
	}

	public RequiredPermissionToSubscribe getPermission() {
		return permission;
	}

	public void setPermission(RequiredPermissionToSubscribe permission) {
		this.permission = permission;
	}

	public Set<UserSO> getModerators() {
		return moderators;
	}

	public void setModerators(Set<UserSO> moderators) {
		this.moderators = moderators;
	}
	
	public Set<EventSO> getEvents() {
		return events;
	}

	public void setEvents(Set<EventSO> events) {
		this.events = events;
	}

	public Set<RequestSO> getRequests() {
		return requests;
	}

	public void setRequests(Set<RequestSO> requests) {
		this.requests = requests;
	}

	public Set<OfferSO> getOffers() {
		return offers;
	}

	public void setOffers(Set<OfferSO> offers) {
		this.offers = offers;
	}

	public Set<CommunityMemberSO> getMembers() {
		return members;
	}

	public void setMembers(Set<CommunityMemberSO> members) {
		this.members = members;
	}

	@Override
	public String toString() {
		return "CommunitySO [name=" + name + ", description=" + description
				+ ", category=" + category + ", privacy=" + privacy
				+ ", permission=" + permission + ", moderators=" + moderators
				+ ", posts=" + posts + ", events=" + events + ", requests="
				+ requests + ", offers=" + offers + ", members=" + members
				+ "]";
	}

}
